package gbench.sandbox.matrix.algebra.numberic;

import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import gbench.common.fs.XlsFile.DataMatrix;
import gbench.commonApp.data.DataMatrixApp;
import static gbench.common.tree.LittleTree.IRecord.*;
import static gbench.commonApp.data.DataMatrixApp.MathOps.*;
import static java.util.Arrays.*;
import static gbench.common.tree.LittleTree.*;

public class JunitQR extends DataMatrixApp{
    
    @Test
    void foo() {
        var mx = DMB(Double.class,3,3).numerics(
           1,-1,0,
           1,0,1,
           1,-1,1
        );
        mx = DSQB(10).numerics(DBLS(100));
        println("数据矩阵");
        println(mx);
        
        final var betas2 = schmidt(mx);
        final var a = DataMatrix.of3(betas2);
        println("schmidt");
        println(a);
        
        final var betas = schmidt_unitize(mx);
        var mx2= DataMatrix.of3(betas);
        println("schmidt_unitize");
        println(mx2);
        
        println(mx2.setHeader((String)null));
        println(mx2.tp().mmult(mx2));
    }
    
    @Test
    void x() {
        var a1 = 
                //A(1,2,3);
                A(1,1,0,0,0);
        var a2 = 
            //A(4,5,6);
            A(-1,0,-1,1,0);
        var proja = proj(a2,a1);
        println(asList(proja));
        var c = sub(a2,proj(a2,a1));
        println("a2:"+asList(a2));
        println("proja:"+asList(proja));
        println("dot(a,b)"+asList(c));
        println(dot(a1,c));
       
    }
    
    @Test
    void bar() {
        var x = Stream.of(1).reduce((a,b)->a);
        println(x);
    }
    
    @Test
    public void oo() {
        println(asList(div2(A(1,2,3,4,5),1)));
        println(asList(div(A(1,2,3,4,5),1)));
    }
    
    @Test
    public void qux() {
        var a=A(1,2,3,4);
        var b=A(5,6,7,8);
        var c= sub(b,proj(b,a));
        println(asList(c));
        println(MFT("dot of {0}",dot(a,c)));
        
        var tt = schmidt(L(a,b));
        println(DataMatrix.of3(tt));
    }
    
    @Test
    public void qux2() {
        var aa = A(1d,2d,3d,5d,6d,8d);
        aa = FA(aa,0d,5);
        aa = FA(null,0d,1);
        println(asList(aa));
    }
    
    @Test
    public void qux3() {
       final var A = DMB(Double.class,4,3).numerics(
           -3, 1, -2,
           1, 1, 1,
           1, -1, 0,
           1, -1,1
        );
       final var b = V(1d,0d,-2d,1d);
       final var U = schmidt_unitize2(A);
       final var R = U.tp().mmult(A);
       final var x = R.inv().mmult(U.tp()).mmult(b);
       println(x);
    }
}
